package TestExercises01;

//数字加密————对密码先加5，再对10求余，然后进行反转，最后进行拼接
public class test06 {
    public static void main(String[] args) {
        int[] arr = {1, 9, 8, 3};
        int[] newArr = new int[arr.length];
        System.out.print("反转前的密码：");
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = (arr[i] + 5) % 10;
            System.out.print(newArr[i] + " ");
        }
        System.out.println();
        int[] newArrArr = fanzhuan(newArr);
        System.out.print("反转后的密码：");
        for (int i = 0; i < newArrArr.length; i++) {
            System.out.print(newArrArr[i] + " ");
        }

        System.out.println();
        int number = 0;
        for (int i = 0; i < newArrArr.length; i++) {
            number = number * 10 + newArrArr[i];
        }
        System.out.println("加密后的密码为：" + number);
    }

    //反转
    public static int[] fanzhuan(int[] arr) {
        for (int i = 0, j = arr.length - 1; i < j; i++, j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        return arr;
    }
}
